package com.yzi.core.schedule
{
	import com.yzi.core.IObservable;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.ProgressEvent;
	
	public class Worker extends EventDispatcher implements IWorker, IObservable
	{
		public function Worker(target:IEventDispatcher = null)
		{
			super(target);
		}
		
		private function onProgress($event:ProgressEvent): void
		{
			dispatchEvent($event);
			if($event.bytesLoaded >= $event.bytesTotal) {
				dispatchEvent(new Event(Event.COMPLETE));
			}
		}
		
		public function Execute($work:ITask):void
		{
			$work.GetReport().AddObserver(this);
			$work.Start();
			dispatchEvent(new Event(Event.ACTIVATE));
		}
		
		public function Update($event:Event=null):void { dispatchEvent($event); }
		
		public function Destory():void
		{
		}		
	}
}